﻿namespace Awaken.Utils.CacheProvider
{
    /// <summary>
    /// 业务类型枚举编码
    /// <para>注意：开始投入使用后，所有已定义的取值不能再做改动！</para>
    /// <para>--------------------------</para>
    /// <para>@Author: cnalexi@gmail.com</para>
    /// <para>@Create: 2012/3/22</para>
    /// </summary>
    public enum SerialType
    {
        /// <summary>
        /// 通常业务[随机]
        /// </summary>
        Normal = 10,

        /// <summary>
        /// 账单 [不随机 从内存器中生成]
        /// </summary>
        Bill = 1010,

        /// <summary>
        /// 订单 [不随机 从内存器中生成]
        /// </summary>
        Order = 1020,

        /// <summary>
        /// 佣金积分储值等钱相关 [不随机 从内存器中生成]
        /// </summary>
        Money = 1030,
    }

    /// <summary>
    /// 流水号业务类型的转换(licenceType: varchar(10), 最多10个字符)
    /// <para>@Author: cnalexi@gmail.com</para>
    /// <para>@Create: 2012/3/22</para>
    /// </summary>
    public class SerialTypeHelper
    {
        /// <summary>
        /// 根据业务类型枚举，获取实际的业务类型和相应前缀
        /// </summary>
        /// <param name="type">业务枚举</param>
        /// <returns></returns>
        public static TypePrefix GetSerialTypeAndPrefix(SerialType type)
        {
            var tp = new TypePrefix { Type = type.ToString().ToLower() };

            switch (type)
            {
                case SerialType.Bill:
                    return tp;
                case SerialType.Order:
                    return tp;
                case SerialType.Money:
                    return tp;
                case SerialType.Normal:
                    tp.IsRandom = true;
                    return tp;
                default:
                    tp.IsRandom = true;
                    return tp;
            }
        }
    }

    /// <summary>
    /// 序列号生成 业务类型前缀
    /// </summary>
    public class TypePrefix
    {
        /// <summary>
        /// 类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 是否由随机生成器生成
        /// </summary>
        public bool IsRandom { get; set; }
    }
}